<?php
/*
Module:		google
Version:	20071128a-DAT
File:		require.php
*/
	function g_search($text)
	{
	global $CONFIG;
		// Grab the search terms
		$terms = trim(substr($text, 7));
		// Needed for the search function
	    $parameters = array(
	       "key"         => $CONFIG['google_key'],
	       "q"           => $terms,
	       "start"       => 0,
	       "maxResults"  => $CONFIG['google_results'],
	       "filter"      => false,
	       "restrict"    => "",
	       "safeSearch"  => false,
	       "lr"          => $CONFIG['google_lr'],
	       "ie"          => "",
	       "oe"          => ""
	    );
	
	    return google_search($parameters);
	}



  	function google_search($parameters)
{

   $soapclient = new soapclient("http://api.google.com/search/beta2"); // [1]
   $result = $soapclient->call("doGoogleSearch", $parameters, "urn:GoogleSearch");
   $searchtime = $result['searchTime'];
   $begin = $start + 1;
   $end = $start + $parameters['maxResults'];
   $total = $result['estimatedTotalResultsCount'];

   if ($total > 0)
   {
      $result = $result['resultElements'];

      for ($i = 0; $i < $parameters['maxResults']; $i++)
      {
         $element = $result[$i];
         $url = $element['URL'];
         $title = $element['title'];
         $snippet = $element['snippet']; // [2]
         $out .= $url ." ";
      }
      return $out;
   }
   else
   {
      return "No Results";
   }
}


?>
